from common.base import open_browser
from page.login_page import LoginPage, login_url


class LoginSctripts(object):
    def __init__( self, driver ):
        self.login_page = LoginPage(driver)
        self.login_page.open_url(login_url)

    def login_flow( self, username, password ):
        """登录不记住密码"""
        self.login_page.input_username(username)
        self.login_page.input_password(password)
        self.login_page.click_submit()

    def login_flow_remember( self, username, password ):
        """记住密码登录"""
        self.login_page.input_username(username)
        self.login_page.input_password(password)
        self.login_page.click_remember()
        self.login_page.click_submit()

    def is_success( self, username ):
        """判断登录是否成功"""
        login_success_loc = ("class name", "f4_b")
        res = self.login_page.is_text_in_element(login_success_loc, username)
        return res

    def jump_home_page( self ):
        """跳转到首页"""
        self.login_page.click_home_page()

    def jump_email( self ):
        """跳转到邮件--找回密码"""
        self.login_page.click_email()

    def jump_msg( self ):
        """跳转到短信验证--找回密码"""
        self.login_page.click_massage()

    def jump_question( self ):
        """跳转到密码问题--找回密码"""
        self.login_page.click_password_question()

    def jump_register( self ):
        """跳转到立即注册页面"""
        self.login_page.click_register()


if __name__ == '__main__':
    driver = open_browser()
    lds = LoginSctripts(driver)
    lds.login_flow("yangjun", "123456")
    print(lds.is_success("yangjun"))
